<template>
  <div id="app-layout">
    <router-view />
    <!-- 导航窗口 -->
    <div class="nav-block">
      <template v-for="(item, index) in navArr">
        <router-link
          v-if="item.isDemo"
          :key="index"
          :to="item.path"
          class="nav-item"
          >{{ item.name }}</router-link
        >
      </template>
      <div class="nav-item theme-btn" @click="handleChangeTheme">主题</div>
    </div>
  </div>
</template>

<script>
import { ref, getCurrentInstance } from "vue";
export default {
  name: "App",
  setup() {
    const { ctx } = getCurrentInstance();
    let currentTheme = ref("");
    let navArr = ref(ctx.$router.options.routes);
    function handleChangeTheme() {
      let bodyDom = document.getElementById("g-body");
      if (currentTheme.value=='dark') {
        currentTheme.value = "default";
        bodyDom.className = "theme-default";
      } else {
        currentTheme.value = "dark";
        bodyDom.className = "dark-page";
      }
    }
    return {
      currentTheme,
      navArr,
      handleChangeTheme,
    };
  },
};
</script>

<style lang="scss" >
#app-layout {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  background-color: #00183e;
  height: 100%;
}

.nav-block {
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);

  .nav-item {
    width: 100px;
    height: 30px;
    line-height: 30px;
    background-color: #fff;
    border: 1px solid rgba(#409eff, 0.8);
    // border-radius: 50%;
    font-size: 16px;
    color: #409eff;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 5px 8px rgba(#000, 0.1);
    transition: all 0.2s;

    &.theme-btn {
      background-color: #e6a23c;
      border-color: #e6a23c;
      color: #fff;
    }

    &:hover {
      transform: translateY(-5px);
    }

    &.router-link-exact-active {
      background-color: rgba(#409eff, 1);
      color: #fff;
    }
  }
}
</style>
